package com.fsnbigdata.repository;
import io.springlets.data.jpa.repository.support.QueryDslRepositorySupportExt;
import org.springframework.roo.addon.layers.repository.jpa.annotations.RooJpaRepositoryCustomImpl;
import com.fsnbigdata.domain.ParkDistrict;
import com.fsnbigdata.domain.Park;
import com.fsnbigdata.domain.QParkDistrict;
import com.querydsl.core.types.Path;
import com.querydsl.jpa.JPQLQuery;
import io.springlets.data.domain.GlobalSearch;
import io.springlets.data.jpa.repository.support.QueryDslRepositorySupportExt.AttributeMappingBuilder;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;

/**
 * = ParkDistrictRepositoryImpl
 *
 * TODO Auto-generated class documentation
 *
 */
@RooJpaRepositoryCustomImpl(repository = ParkDistrictRepositoryCustom.class)
@Transactional(readOnly = true)
public class ParkDistrictRepositoryImpl extends QueryDslRepositorySupportExt<ParkDistrict> implements ParkDistrictRepositoryCustom {

    /**
     * TODO Auto-generated constructor documentation
     */
    ParkDistrictRepositoryImpl() {
        super(ParkDistrict.class);
    }

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    public static final String IMAGE = "image";

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    public static final String DESCRIPTION = "description";

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    public static final String PARK = "park";

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    public static final String NAME = "name";

    /**
     * TODO Auto-generated method documentation
     *
     * @param park
     * @param globalSearch
     * @param pageable
     * @return Page
     */
    public Page<ParkDistrict> findByPark(Park park, GlobalSearch globalSearch, Pageable pageable) {
        QParkDistrict parkDistrict = QParkDistrict.parkDistrict;
        JPQLQuery<ParkDistrict> query = from(parkDistrict);
        Assert.notNull(park, "park is required");
        query.where(parkDistrict.park.eq(park));
        Path<?>[] paths = new Path<?>[] { parkDistrict.park, parkDistrict.name, parkDistrict.description, parkDistrict.image };
        applyGlobalSearch(globalSearch, query, paths);
        AttributeMappingBuilder mapping = buildMapper().map(PARK, parkDistrict.park).map(NAME, parkDistrict.name).map(DESCRIPTION, parkDistrict.description).map(IMAGE, parkDistrict.image);
        applyPagination(pageable, query, mapping);
        applyOrderById(query);
        return loadPage(query, pageable, parkDistrict);
    }
}
